#!/bin/bash
# 工程造价政策助手环境验证脚本
# 版本: 1.0.0

echo "=== 工程造价政策助手环境验证 ==="
echo "验证时间: $(date)"
echo ""

# 1. 验证Python环境
echo "--- Python环境 ---"
python -c "
import sys, pkg_resources
print(f'Python版本: {sys.version.split()[0]}')
print(f'执行路径: {sys.executable}')

required = {'pychm', 'beautifulsoup4', 'python-docx', 'llama-index', 
            'chromadb', 'sentence-transformers', 'streamlit', 'loguru'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed

if missing:
    print(f'缺少的包: {missing}')
else:
    print('所有Python依赖已安装')
"
echo ""

# 2. 验证Ollama环境
echo "--- Ollama环境 ---"
if command -v ollama &> /dev/null; then
    echo "Ollama版本: $(ollama --version)"
    echo "已安装模型:"
    ollama list | awk '{print "- " $0}'
else
    echo "Ollama未安装或不在PATH中"
fi
echo ""

# 3. 验证核心功能
echo "--- 核心功能测试 ---"
echo "1. CHM解析器:"
python -c "import pychm; print('pychm模块可用')" 2>/dev/null || echo "pychm模块不可用"

echo "2. 向量数据库:"
python -c "import chromadb; print('chromadb模块可用')" 2>/dev/null || echo "chromadb模块不可用"

echo "3. 流式界面:"
python -c "import streamlit; print('streamlit模块可用')" 2>/dev/null || echo "streamlit模块不可用"
echo ""

# 4. 系统信息
echo "--- 系统信息 ---"
echo "操作系统: $(uname -a)"
echo "内存信息: $(free -h | awk '/Mem:/{print $2}')"
echo ""

echo "验证完成!"
echo "详细报告已生成: env_check_$(date +%Y%m%d).log"